<?php

require_once('include/MVC/View/views/view.list.php');

class OpportunitiesViewList extends ViewList{

    function listViewProcess(){
            $no = $this->getNumberOfMeetings();
            $this->processSearchForm();
            $this->lv->searchColumns = $this->searchForm->searchColumns;

            if(!$this->headers)
                    return;
            if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
                    $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
                    $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
                    $moduleListTitle = $GLOBALS['mod_strings']['LBL_LIST_FORM_TITLE'] . $savedSearchName. ' - '.$no.' '.$GLOBALS['mod_strings']['LBL_CURRENT_MONTH'];
                    echo get_form_header($moduleListTitle, '', false);
                    echo $this->lv->display();
            }
    }

    function getNumberOfMeetings(){
        $from = date('Y-m').'-01 00:00:00';
        $to = date('Y-m-t').' 23:59:59';
        global $current_user;
        $query = "SELECT count(*) as no FROM opportunities o
            WHERE o.date_entered >= '$from' AND o.date_entered <= '$to'
            AND o.created_by = '$current_user->id'
            AND o.sales_stage = 'Closed Won'
            AND o.deleted = 0";

        $result = $GLOBALS['db']->query($query);
        $row = $GLOBALS['db']->fetchByAssoc($result);
        return $row['no'];
    }
}